/**
 * File: PageRetriever.java
 * TCSS 422 Team Project 1
 * Autumn 2009
 * Team Members: Darin Cyr, Kirk Leonard, John Patanian
 */

package singlethread;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import javax.swing.text.html.HTMLEditorKit.Parser;

/**
 * Retrieves web pages and stores them for later analysis by PageParser.
 * @author Darin Cyr
 * @author Kirk Leonard
 * @author John Patanian
 * @version Autumn 2009
 *
 */
public class PageRetriever 
{
  /**
  * Takes a reference to the urlList to pass to the parser, the current url we're
  * working with, and the pageCount (passed to parser to generate file names).
  * Calls the parser for the current page.
  * @param the_url_list The list of URLs to retrieve.
  * @param the_url The seed url.
  * @param the_page_count The page count.
  */
  public PageRetriever(final URLBucket the_url_list, 
    final URL the_url, final int the_page_count)
  {
	  
    try
    {
      final URLConnection connection = the_url.openConnection();
      final InputStream is = connection.getInputStream();

      final Parser a_parser = new HTMLParse().getParser();
      a_parser.parse(new InputStreamReader(is),
        new PageParser(the_url_list, the_url, the_page_count), true);
    }
    catch (final IOException e)
    {
      //System.out.println("IOException trying to open connection to page " + e);
    }
  }

}
